public class QuadraticEquation {
    private int a;
    private int b;
    private int c;

    public QuadraticEquation(int a, int b, int c) {
        this.a = a;
        this.b = b;
        this.c = c;
        getResult();
    }

    /**
     * 判断 b^2-4ac 的值
     * 为正数返回1 0返回0 负数返回-1
     * @return result
     */
    private int getDiscriminant() {
        int result = 0;
        if ((b*b - 4*a*c) > 0)  result = 1;
        else if ((b*b - 4*a*c) == 0)    result = 0;
        else result = -1;
        return result;
    }

    /**
     * 计算第一个根
     * @return
     */
    private double getRoot1() {
        double r1 = (-b + Math.sqrt(b*b - 4*a*c)) / (2 * a);
        return r1;
    }

    /**
     * 计算第二个根
     * @return
     */
    private double getRoot2() {
        double r2 = (-b - Math.sqrt(b*b - 4*a*c)) / (2 * a);
        return r2;
    }

    private void getResult() {
        if (getDiscriminant() == -1)
            System.out.println("The equation has no roots.");
        else if (getDiscriminant() == 0)
            System.out.println(getRoot1());
        else {
            System.out.print(getRoot1() + " " + getRoot2());
        }
    }


}
